<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>主页</title>
        <script type='text/javascript' src="../static/js/jquery-3.3.1.min.js"></script>
    </head>
    <body>
        <h1>登陆成功，这是主页！</h1>
        <div id="allLoginInfo">
            <h2>用户登录日志信息</h2>
            <div id="info">
            </div>
        </div>
    </body>
</html>
<script>
    $(function(){
        $.ajax({
            url:"/allLoginInfo",
            type:"get",
            data: null,
            contentType:false,
            processData: false,
            async: false,
            cache : false,
            // contentType:"application/json;charset=utf-8",
            success:function(result){
                // console.log(result);
                $.each(result,function (index,item){
                    console.log(item);
                    $("<div>用户名："+item["username"]+
                        "&nbsp;&nbsp;   ip地址："+item["ip"]+
                        "&nbsp;&nbsp;   访问时间："+TimestampToDate(item["time"])+
                        "<div/>").appendTo("#info");
                })
            }
        })

        function TimestampToDate(Timestamp) {
            let date1 = new Date(Timestamp);
            return date1.toLocaleDateString().replace(/\//g, "-") + " " + date1.toTimeString().substr(0, 8);
        }
    });
</script>
